
/**
 * @author Adam Blackwell & Ryan Cassidy 
 */
// to represent a premium checking account in a bank
public class PremiumChecking extends Checking{
	
	int points;

	/**
	 * @param accountNum
	 * @param balance
	 * @param name
	 * @param minimum
	 * @param points 
	 */
	public PremiumChecking(int accountNum, int balance, String name, int minimum, int points) {
		super(accountNum, balance, name, minimum);
		this.points = points;
	}
	
	/* TEMPLATE:
	 * FIELDS:
	 * 	... accountNum ...    -- int
	 * 	... balance ...       -- int
	 * 	... name ...          -- String
	 *  ... minimum ...       -- int
	 *  ... points ...         -- int
	 *  
	 *  METHODS:
	 *  ... deposit(int amt) ...     -- IAccount
	 *  ... withdraw(int amt) ...    -- IAccount
	 */
	
	// produce an updated account after depositing the given amount
	public IAccount deposit(int amt){
		return new PremiumChecking(this.accountNum, this.balance + amt, 
		                    this.name, this.minimum, this.points + this.points + (amt / 20));
	}
	
	// produce an updated account after withdrawing the given amount
	public IAccount withdraw(int amt){
		if (this.balance - this.minimum >= amt){
			return new PremiumChecking(this.accountNum, this.balance - amt, 
                          this.name, this.minimum, this.points);
		}
		else {
			throw new RuntimeException("Insufficient Funds in the checking account.");
		}
	}

	@Override
	// Checks if this account is a Checking account.
	public boolean isChecking(){
		return false;
	}
	
	@Override
	// Checks if this account is a Checking account (It is).
	public boolean isPremiumChecking(){
		return true;
	}
	
	@Override
	// Turns the account into a Checking account.
	public  PremiumChecking toPremiumChecking(){
		return this;
	}
	
	
//	@Override
//	// Checks if two accounts are the same.
//	public boolean same(IAccount that) {
//		if(that.isPremiumChecking()){
//			return that.toPremiumChecking().samePremiumChecking(this);
//		} else {
//			return false;
//		}
//	}
	
	// Use instance of.
	@Override
	// Checks if two accounts are the same.
 	public boolean same(IAccount that){
		if (that instanceof PremiumChecking){
			return ((PremiumChecking)that).samePremiumChecking(this);
		} else {
			return false;
		}
	}
	
	// Rewriting to use instanceOf
//	@Override
//	// Checks if two accounts are the same.
//	public boolean same(IAccount that) {
//		if(that.isPremiumChecking()){
//			return that.toPremiumChecking().samePremiumChecking(this);
//		} else {
//			return false;
//		}
//	}

	// Compares the fields of two Checking accounts.
	public boolean samePremiumChecking(PremiumChecking that){
		return 
		this.name.equals(that.name) &&
		this.minimum == that.minimum &&
		this.balance == that.balance &&
		this.accountNum == that.accountNum &&
		this.points == that.points;
	}
}
